#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

#include <stdio.h>

int main() {
    int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    int y = 0;
    int m = 0;
    while (scanf("%d %d", &y, &m) != EOF)
    {
        int days = a[m];
        if ((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0) && m == 2)
        {
            days++;
        }
        printf("%d\n", days);
    }
    return 0;
}